package com.annhoa.interfaces.facade;

import java.sql.Timestamp;
import java.util.logging.Logger;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.annhoa.infrastructure.common.BasePage;
import com.annhoa.infrastructure.common.PageData;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.servlet.ModelAndView;


public class BaseController {

    protected BasePage webpage;

    /**
     * 得到PageData
     */
    public PageData getPageData() {
        return new PageData(this.getRequest());
    }

    /**
     * 得到ModelAndView
     */
    public ModelAndView getModelAndView() {
        return new ModelAndView();
    }

    /**
     * 得到request对象
     */
    public HttpServletRequest getRequest() {
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes())
                .getRequest();
        return request;
    }

    /**
     * 得到response对象
     */
    public HttpServletResponse getResponse() {
        HttpServletResponse response = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes())
                .getResponse();
        response.setHeader("Access-Control-Allow-Origin", "*");
        return response;
    }

    /**
     * 得到Timestamp(String)
     */
    public String getTimestamp() {
        return new Timestamp(System.currentTimeMillis()).toString();
    }

    /**
     * 得到分页列表的信息
     */
    public BasePage getBasePage() {

        return new BasePage();
    }

}
